/**
 * www.ricardo-dunkel.de
 * 
 * -- Copyright 2008-2009
 * by Dunkel, Ricardo --
 *  
 */
package de.ricardodunkel.gwtspot.client.api.ui.common;

import com.google.gwt.user.client.ui.Tree;

/**
 * Common {@link Tree} widget utility class.
 * 
 * @author Dunkel, Ricardo
 * 
 * @version 0.1
 * 
 */
public class TreeUtility {

	/**
	 * Does remove item selection of a given {@link Tree}.
	 * 
	 * @param tree  A tree where selection should be removed.
	 */
	public static void unselectAll(Tree tree) {
		invertSelection(tree, false);
	}
	
	/**
	 * Does select all items of a given {@link Tree}.
	 * 
	 * @param tree  A tree where selection should be executed on.
	 */
	public static void selectAll(Tree tree) {
		invertSelection(tree, true);
	}
	
	/**
	 * Does invert a trees item selection.
	 * 
	 * @param tree  A tree where selection should be inverted.
	 * @param selection  A choice of selection for tree items.
	 */
	public static void invertSelection(Tree tree, boolean selection) {
		for (int i = 0; i < tree.getItemCount(); i++) {
			tree.getItem(i).setSelected(selection);
		}
	}
	
}
